package com.zhiwang.planet.mvvm.viewmodel.my

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
import com.zhiwang.planet.di.ActivityScope
import com.zhiwang.planet.mvvm.model.RestApi
import com.zhiwang.planet.util.Toaster
import com.zhiwang.planet.util.arrange
import com.zhiwang.planet.util.arrangeComplete
import io.reactivex.functions.Action
import io.reactivex.functions.Consumer
import javax.inject.Inject

@ActivityScope
open class ChangeNickNameViewModel @Inject constructor(var restApi: RestApi, var scopeProvider: AndroidLifecycleScopeProvider)
    : ViewModel() {


    val nickName = MutableLiveData<String>()

    val name = MutableLiveData<String>()


    fun randomNickName() {
        restApi.randomNickName()
                .arrange(Consumer {
                    nickName.value = it
                }, null)
    }

    fun submit() {
        restApi.setNickName(nickName.value ?: "")
                .arrangeComplete(Action {
                    load()
                    Toaster.message("修改成功")
                }, {
                   it.message?.apply { Toaster.message(this) }
                })
    }

    fun load() {
//        restApi.getUserInfoEx()
//                .arrange(Consumer {
//                    name.value = it.userName
//                },{
//
//                })
    }
}